<?php
namespace app\admin\controller;


use think\facade\Config;
use app\admin\AdminBase;
use think\facade\Db;
use think\facade\Session;
use think\facade\Validate;
use think\exception\ValidateException;
use think\wenhainan\Auth;
use app\admin\model\AuthRule as AuthRuleModel;
/**
 * 后台登录
 * Class Login
 * @package app\admin\controller
 */
class Index extends AdminBase
{

    /* 后台首页
    * @return mixed
    */
    public function index()
    {
        return $this->fetch("index");
    }
    //初始项目菜单
    public function initMemu(){
        $auth     = new Auth();
        $id = Session::get("admin_id");
        $auth_rule_list = AuthRuleModel::where(['status'=> 1,'pattern'=>1])
            ->order('sort' ,'DESC')->order('id' ,'DESC')
            ->field("id,pid,name as href,title,icon,sort")->select()->toArray();
        $menu = [];
        foreach ($auth_rule_list as &$value) {
            if ($auth->check($value['href'], $id) || $id == 1) {
                $value['href'] = '/'.$value['href'];
                $menu[] = $value;
            }
        }
        $menu = !empty($menu)?array2tree($menu,'pid','child') : [];
        $data["homeInfo"] = [
            "title"=> "首页",
            "href"=> '/admin/home/index'
        ];
        $host = $this->request->domain();

        $data["logoInfo"] = [
            "title"=> config("app.app_name"),
            "image"=> '/favicon.ico',
            "href"=> ""];

        $data["menuInfo"] = $menu;
        return json($data);
    }
}